﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MVVMWinrt.UnitTests.TestClasses.SimpleObjects;
#if DOT_NET
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
#endif
using StyleMVVM.UnitTests.TestClasses.SimpleObjects;
using StyleMVVM.DependencyInjection;
using StyleMVVM.Utilities;

namespace StyleMVVM.UnitTests.DependencyInjection
{
	[TestClass]
	public class DependencyInjectionContainerTests : BaseTestClass
	{
		[TestMethod]
		public void ExportDefaultConstructorTest()
		{
			DefaultConstructorExport a =
				bootstrapper.Container.Locate<DefaultConstructorExport>();

			Assert.IsNotNull(a);
			Assert.IsNotNull(a.B);
		}

		[TestMethod]
		public void ExportInterfaceTest()
		{
			ITestInterface a =
				bootstrapper.Container.Locate<ITestInterface>();

			Assert.IsNotNull(a);
			Assert.IsNotNull(a.SimpleImport);
		}

		[TestMethod]
		public void ExportGenericInterfaceTest()
		{
			IGenericTestInterface<int> a = bootstrapper.Container.Locate<IGenericTestInterface<int>>();

			Assert.IsNotNull(a);
			Assert.IsNotNull(a.TestInterface);
		}

		[TestMethod]
		public void MultipleConstructorTest()
		{
			MultipleConstructorExport created =
				bootstrapper.Container.Locate<MultipleConstructorExport>();

			Assert.IsNotNull(created, "Default Constructor");

			created = bootstrapper.Container.Locate<MultipleConstructorExport>(1);

			Assert.IsNotNull(created, "one int");
			Assert.AreEqual(1, created.X);

			created = bootstrapper.Container.Locate<MultipleConstructorExport>(1, 2);

			Assert.IsNotNull(created, "two int");
			Assert.AreEqual(1, created.X);
			Assert.AreEqual(2, created.Y);

			created = bootstrapper.Container.Locate<MultipleConstructorExport>(1, 2.0);

			Assert.IsNotNull(created, "red int, blue int");
			Assert.AreEqual(1, created.X);
			Assert.AreEqual(2.0, created.Z);
		}

		[TestMethod]
		public void StringConstructorTest()
		{
			MultipleConstructorExport created = bootstrapper.Container.Locate<MultipleConstructorExport>(
				ContainerHelper.SingleNull);

			Assert.IsNotNull(created);
			Assert.AreNotEqual(MultipleConstructorExport.DefaultConstructorValue, created.X);
		}

		[TestMethod]
		public void MultipleExportTest()
		{
			IMultipleExportInterface interface1 = bootstrapper.Container.Locate<IMultipleExportInterface>();

			IMultipleExportInterface2 interface2 = bootstrapper.Container.Locate<IMultipleExportInterface2>();

			IMultipleExportInterface3 interface3 = bootstrapper.Container.Locate<IMultipleExportInterface3>();

			Assert.IsTrue(ReferenceEquals(interface1, interface2));
			Assert.IsTrue(ReferenceEquals(interface2, interface3));
		}
	}
}